<?php

namespace app\admin\model;

use think\Model;

class VisitingMaterials extends Model
{

    // 表名
    protected $name = 'visiting_materials';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_voter_text',
    ];

    public function getIsVoterList()
    {
        return ['1' => __('Is_voter 1'), '2' => __('Is_voter 2')];
    }

    public function getIsVoterTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_voter']) ? $data['is_voter'] : '');
        $list  = $this->getIsVoterList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getGenderList()
    {
        return ['1' => __('Gender 1'), '2' => __('Gender 2')];
    }

    public function getGenderTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['gender']) ? $data['gender'] : '');
        $list  = $this->getGenderList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getEducationList()
    {
        return ['1' => __('visitingmaterials.education 1'), '2' => __('visitingmaterials.education 2'), '3' => __('visitingmaterials.education 3'), '4' => __('visitingmaterials.education 4')];
    }

    public function getEducationTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['education']) ? $data['education'] : '');
        $list  = $this->getEducationList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCognitiveApproachList()
    {
        return ['1' => __('visitingmaterials.cognitive_approach 1'), '2' => __('visitingmaterials.cognitive_approach 2'), '3' => __('visitingmaterials.cognitive_approach 3'), '4' => __('visitingmaterials.cognitive_approach 4'), '5' => __('visitingmaterials.cognitive_approach 5'), '6' => __('visitingmaterials.cognitive_approach 6'), '7' => __('visitingmaterials.cognitive_approach 7'), '8' => __('visitingmaterials.cognitive_approach 8'), '9' => __('visitingmaterials.cognitive_approach 9'), '10' => __('visitingmaterials.cognitive_approach 10'), '11' => __('visitingmaterials.cognitive_approach 11')];
    }

    public function getCognitiveApproachTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cognitive_approach']) ? $data['cognitive_approach'] : '');
        $list  = $this->getCognitiveApproachList();
        return isset($list[$value]) ? $list[$value] : '';
    }
}
